package com.example.english.service.Impl;

import com.example.english.mapper.StudentMapper;
import com.example.english.pojo.PageBean;
import com.example.english.pojo.Student;
import com.example.english.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    /**
     *   查询所有学生四级成绩
     */
    @Override
    public PageBean list(Integer pageNum, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.list();
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }


    /**
     *   添加学生
     */
    @Override
    public void add(Student student) {
        studentMapper.add(student);
    }


    /**
     *   删除学生
     */
    @Override
    public void delete(Long id) {
        studentMapper.delete(id);
    }


    /**
     *   修改学生
     */
    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public PageBean BySerialNumber(Integer pageNum, Integer pageSize, Long inputKeyword) {
//设置分页参数
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.BySerialNumber(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByStudentId(Integer pageNum, Integer pageSize, Integer inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByStudentId(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByName(Integer pageNum, Integer pageSize, String inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByName(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByGender(Integer pageNum, Integer pageSize, String inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByGender(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByAge(Integer pageNum, Integer pageSize, Integer inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByAge(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByPhoneNumber(Integer pageNum, Integer pageSize, Long inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByPhoneNumber(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean ByGrades(Integer pageNum, Integer pageSize, Integer inputKeyword) {
        PageHelper.startPage(pageNum, pageSize);

        //执行查询操作
        List<Student> appointmentList = studentMapper.ByGrades(inputKeyword);
        Page<Student> p = (Page<Student>) appointmentList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
}
